//
//  SettingViewController.m
//  SlothSecondProj
//
//  Created by 焱 孙 on 14-3-22.
//  Copyright (c) 2014年 visionet. All rights reserved.
//

#import "SettingViewController.h"
#import "AboutViewController.h"
#import "GroupAndUserDao.h"
#import "Utils.h"
#import "LanguageViewController.h"
#import "EditPasswordViewController.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initView
{
    self.view.backgroundColor = [UIColor whiteColor];
    //左边按钮
    UIButton *btnBack = [Utils buttonWithImageName:[UIImage imageNamed:@"nav_setting"] frame:[Utils getNavLeftBtnFrame:CGSizeMake(100,76)] target:self action:nil];
    [btnBack addTarget:self action:@selector(showSideMenu) forControlEvents:UIControlEventTouchUpInside];
    [self setLeftBarButton:btnBack];
    //notice num view
    NoticeNumView *noticeNumView = [[NoticeNumView alloc]initWithFrame:CGRectMake(25.5, 6+kStatusBarHeight, 18, 18)];
    [self.view addSubview:noticeNumView];
    
    [self setTopNavBarTitle:[Common localStr:@"Menu_Setting" value:@"设置"] andKey:@"Menu_Setting"];
    
    CGFloat fHeight = NAV_BAR_HEIGHT+20.0;
    
    //bk
    self.imgViewSettingBK = [[UIImageView alloc]initWithFrame:CGRectMake(0, fHeight, kScreenWidth, 40*1)];
    self.imgViewSettingBK.image = [[UIImage imageNamed:@"groupedit_cell_bk"] stretchableImageWithLeftCapWidth:160 topCapHeight:20];
    [self.view addSubview:self.imgViewSettingBK];
    
//    //clear buffer
//    self.imgViewClearBufferArrow = [[UIImageView alloc]init];
//    self.imgViewClearBufferArrow.frame = CGRectMake(kScreenWidth-28, fHeight+(40-13)/2, 13, 13);
//    self.imgViewClearBufferArrow.image = [[UIImage imageNamed:@"cell_right_arrow"] stretchableImageWithLeftCapWidth:150.5 topCapHeight:15];
//    [self.view addSubview:self.imgViewClearBufferArrow];
//    
//    self.btnClearBuffer = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.btnClearBuffer.frame = CGRectMake(11, fHeight+2, kScreenWidth-22, 40-4);
//    [self.btnClearBuffer setTitleColor:COLOR(51, 51, 51, 1.0) forState:UIControlStateNormal];
//    [self.btnClearBuffer setTitleColor:COLOR(136, 136, 136, 1.0) forState:UIControlStateHighlighted];
//    [self.btnClearBuffer.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:16.0]];
//    [self.btnClearBuffer setTitle:@"清除缓存" forState:UIControlStateNormal];
//    CGSize size = [Common getStringSize:self.btnClearBuffer.titleLabel.text font:self.btnClearBuffer.titleLabel.font bound:CGSizeMake(MAXFLOAT, 20) lineBreakMode:self.btnClearBuffer.titleLabel.lineBreakMode];
//    self.btnClearBuffer.titleEdgeInsets = UIEdgeInsetsMake(0, -(self.btnClearBuffer.frame.size.width-size.width)+15, 0, 0);
//    [self.btnClearBuffer setBackgroundImage:[Common getImageWithColor:COLOR(150, 150, 150, 0.4)] forState:UIControlStateHighlighted];
//    [self.btnClearBuffer.layer setBorderWidth:1.0];
//    [self.btnClearBuffer.layer setCornerRadius:3];
//    self.btnClearBuffer.layer.borderColor = [[UIColor clearColor] CGColor];
//    [self.btnClearBuffer.layer setMasksToBounds:YES];
//    [self.btnClearBuffer addTarget:self action:@selector(clickSettingBtn:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:self.btnClearBuffer];
//    
//    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(10, fHeight+39.5, kScreenWidth-20, 0.5)];
//    viewLine.backgroundColor = COLOR(204, 204, 204, 1.0);
//    [self.view addSubview:viewLine];
//    fHeight +=40;
    
    //修改密码
    self.imgViewModifyPwdArrow = [[UIImageView alloc]init];
    self.imgViewModifyPwdArrow.frame = CGRectMake(kScreenWidth-28, fHeight+(40-13)/2, 13, 13);
    self.imgViewModifyPwdArrow.image = [[UIImage imageNamed:@"cell_right_arrow"] stretchableImageWithLeftCapWidth:150.5 topCapHeight:15];
    [self.view addSubview:self.imgViewModifyPwdArrow];
    
    self.btnModifyPwd = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnModifyPwd.frame = CGRectMake(11, fHeight+2, kScreenWidth-22, 40-4);
    [self.btnModifyPwd setTitleColor:COLOR(51, 51, 51, 1.0) forState:UIControlStateNormal];
    [self.btnModifyPwd setTitleColor:COLOR(136, 136, 136, 1.0) forState:UIControlStateHighlighted];
    [self.btnModifyPwd.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:16.0]];
    [self.btnModifyPwd setTitle:[Common localStr:@"Setting_Clear_Cache" value:@"修改密码"] forState:UIControlStateNormal];
    CGSize size = [Common getStringSize:self.btnModifyPwd.titleLabel.text font:self.btnModifyPwd.titleLabel.font bound:CGSizeMake(MAXFLOAT, 20) lineBreakMode:self.btnModifyPwd.titleLabel.lineBreakMode];
    self.btnModifyPwd.titleEdgeInsets = UIEdgeInsetsMake(0, -(self.btnModifyPwd.frame.size.width-size.width)+15, 0, 0);
    [self.btnModifyPwd setBackgroundImage:[Common getImageWithColor:COLOR(150, 150, 150, 0.4)] forState:UIControlStateHighlighted];
    [self.btnModifyPwd.layer setBorderWidth:1.0];
    [self.btnModifyPwd.layer setCornerRadius:3];
    self.btnModifyPwd.layer.borderColor = [[UIColor clearColor] CGColor];
    [self.btnModifyPwd.layer setMasksToBounds:YES];
    [self.btnModifyPwd addTarget:self action:@selector(clickSettingBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btnModifyPwd];
}

- (void)showSideMenu
{
    [[NSNotificationCenter defaultCenter]postNotificationName:kDrawerOpenLeftSide object:nil];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:kDrawerAddPanGesture object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:kDrawerRemovePanGesture object:nil];
}

-(void)clickSettingBtn:(UIButton*)sender
{
    if (sender == self.btnModifyPwd)
    {
        //修改密码
        EditPasswordViewController *editPasswordViewController = [[EditPasswordViewController alloc]initWithNibName:@"EditPasswordViewController" bundle:nil];
        [self.navigationController pushViewController:editPasswordViewController animated:YES];
    }
    else if (sender == self.btnClearBuffer)
    {
        //清除UIWebView cache
        [BusinessCommon clearAllUIWebViewData];
    }
}

@end
